#ifndef USER_DAO_H
#define USER_DAO_H

#include "SingleClass.h"
#include "mysqlPool.h"
#include <string>
#include "nlohmann/json.hpp"

struct search_user_res{
    std::string tar_user_name;
    bool is_already_friend;
};


class user_dao:public SingleClass<user_dao>{

public:
    //再抽象一层，用于
    std::shared_ptr<mysqlConnection> new_get_con();
    void new_return_con(std::shared_ptr<mysqlConnection>&);
    //逻辑查询函数---查找目标名称并双方判断是否好友---这个就不改了
    struct search_user_res search_user(const std::string &from_user_email,const std::string &tar_user_email);
    //判断好友请求是否重复
    bool friend_apply_is_repeat(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &from_email,const std::string &to_email);
    //写入friend_apply
    bool add_friend_apply(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &from_email,const std::string &to_email,const std::string &varify_text);
    //更改好友申请状态
    int modify_apply_list(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &from_email,const std::string &to_email,const int & apply_res);
    //增加好友--双向增加
    int add_friend_list(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &from_email,const std::string &to_email);
    //查询好友列表
    void search_friend_list(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &user_email,nlohmann::json &user_info_json);
    //查询自己发送的好友申请
    void search_apply_list_from_self(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &user_email,nlohmann::json &user_info_json);
    //查询他人发送的好友申请
    void search_apply_list_from_other(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &user_email,nlohmann::json &user_info_json);
    //暂时持久化聊天文本消息
    void insert_message(std::shared_ptr<mysqlConnection> &mysql_con,const std::string &from_email,const std::string &to_email,const int& msg_type,const std::string &msg_id,const std::string msg_data);

    
private:
    friend class SingleClass<user_dao>;
    mysqlPool pool;
    user_dao()=default;

};



#endif